<?php

require_once('dataSource.php');
require_once('ingredientDao.php');
require_once('labelDao.php');
require_once('recipeDao.php');
require_once('userDao.php');
require_once('recipe-labelDao.php');

function login($login,$password) {

	$encryptedPassword = md5($password);
	$user = findUserByLogin($login);

	if ($user) {

		if ($encryptedPassword == $user["password"])
			return true;
		else
			return false;

	}
	else{

		return false;
		
	}
	

}// end login


function createRecipe($recipe,$ingredients,$labels) {

	$recipeId = insertRecipe($recipe["title"],$recipe["preparation"],$recipe["image"],date("D, Y-m-d H:i:s"));
	foreach($ingredients as $ingredient) {
		insertIngredient($recipeId,$ingredient);
	}

	foreach($labels as $label) {
		$labelResult = findLabelByName($label);
		if (!$labelResult) {
			$labelId = insertLabel($label);
		}
		else
			$labelId = $labelResult["labelId"];
	
		insertRecipeLabel($recipeId,$labelId);

	}




}// en createRecipe


?>